/*
 * User: user
 * Date: 09/02/2008
 * Time: 23:55:38
 */
package org.conann.metadata.validation;

import org.conann.metadata.records.MethodRecord;
import org.conann.metadata.records.Record;
import org.conann.metadata.records.TypeRecord;

import java.util.HashMap;
import java.util.Map;

public class ValidationHandler {

    private static final ValidationHandler instance = new ValidationHandler();

    private final Map<Class<? extends Record>, RecordValidator<?>> validators = new HashMap<Class<? extends Record>, RecordValidator<?>>();

    private ValidationHandler() {
        initialize();
    }

    public void validate(Record<?> record) {
        RecordValidator<Record<?>> validator = (RecordValidator<Record<?>>) validators.get(record.getClass());
        validator.validate(record);
    }

    private void initialize() {
        validators.put(TypeRecord.class, new TypeValidator());
        validators.put(MethodRecord.class, new MethodValidator());
    }

    public static ValidationHandler getInstance () {
        return instance;
    }
}